jQuery.noConflict();

(function($){
	var searchField = $('#SearchForm_SearchForm_Search');
	var default_value = searchField.val();
	searchField.focus(function() {
		$(this).addClass('active');
		if(searchField.val() == default_value) {
			searchField.val('');
		}
	});
	searchField.blur(function() {
		$(this).removeClass('active');
		if(searchField.val() == '') {
			searchField.val(default_value);
		}
	});
			
	if (!$.browser.msie || ($.browser.msie && (parseInt($.browser.version, 10) > 8))) {									 
		var mobile = false;
		var changed = false;
		
		$('body').append('<div id="media-query-trigger"></div>');
		
		function menuWidthCheck() {								  
			if ($(window).width() <= 768) {
				$('body').addClass('tablet-nav');
			}
			else {
				$('body').removeClass('tablet-nav');				
			}
			
			mobile_old = mobile;
			if ($('#media-query-trigger').css('visibility') == 'hidden') {
				mobile = false;
			}
			else {
				mobile = true;
			}
			
			if (mobile_old != mobile) {
				changed = true;
			}
			else {
				changed = false;
			}
		}
		
		menuWidthCheck();
		
		$(window).resize(function() {
			menuWidthCheck();
		});
	}
	
	// offset carvas
	$('[data-toggle="offcanvas"]').click(function () {
    	$('.row-offcanvas').toggleClass('active');
  	});
	
	// scroll-to-top animate
	$(window).scroll(function() {
		if ($(this).scrollTop() > 100) {
			$('#scrollup').fadeIn();
		} else {
			$('#scrollup').fadeOut();
		}
	});

	$('#scrollup').click(function(e) {
		e.preventDefault();
		$("html, body").animate({
			scrollTop : 0
		}, 600);
	});
	
	$('.language').live('click', function(e) {
		e.preventDefault();
		var name = 'locale';
		var value = $(this).data('locale');
		var url = window.location.href;
	    if (url.indexOf(name + "=") >= 0){
	        var prefix = url.substring(0, url.indexOf(name));
	        var suffix = url.substring(url.indexOf(name));
	        suffix = suffix.substring(suffix.indexOf("=") + 1);
	        suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
	        url = prefix + name + "=" + value + suffix;
	    }
	    else{
	    	if (url.indexOf("?") < 0){
	        	url += "?" + name + "=" + value;
	       	}
	    	else{
	        	url += "&" + name + "=" + value;
			}
	    }
	    window.location.href = url;
	});
	
	// ADD SLIDEDOWN ANIMATION TO DROPDOWN //
	$('.dropdown').on('show.bs.dropdown', function(e){
    	$(this).parents(".table-responsive").toggleClass("res-drop");
  	});
  	
  	$('.btn-group').on('show.bs.dropdown', function(e){
    	$(this).parents(".table-responsive").toggleClass("res-drop");
  	});

  	// ADD SLIDEUP ANIMATION TO DROPDOWN //
  	$('.dropdown').on('hide.bs.dropdown', function(e){
    	$(this).parents(".table-responsive").toggleClass("res-drop");
  	});
  	
  	$('.btn-group').on('hide.bs.dropdown', function(e){
    	$(this).parents(".table-responsive").toggleClass("res-drop");
  	});
}(jQuery));
